namespace QMVnSoft.Invoices
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.Controls.ChildGridControls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCTSXLister : FormLister
    {
        private StatusColumn Column1;
        private DataGridViewTextBoxColumn Column10;
        private DataGridViewTextBoxColumn Column11;
        private DataGridViewTextBoxColumn Column13;
        private DataGridViewTextBoxColumn Column14;
        private StatusColumn Column2;
        private NumericColumn Column22;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private DataGridViewTextBoxColumn Column5;
        private DataGridViewTextBoxColumn Column6;
        private DataGridViewTextBoxColumn Column7;
        private DataGridViewTextBoxColumn Column8;
        private DataGridViewTextBoxColumn Column9;
        private IContainer components;
        private GridControl grdDetail;
        private GridControl grdMaster;
        private SplitContainer GridContainer;
        private object id_Ngay_Ct1;
        private object id_Ngay_Ct2;
        private int ii_FilterByUser;
        private int ii_Locked;
        private int ii_Posted;
        private object is_Dien_Giai;
        private object is_Ghi_Chu;
        private object is_Ma_Bp;
        private object is_Ma_Hd;
        private object is_Ma_Loai1;
        private object is_Ma_Loai2;
        private object is_Ma_Loai3;
        private object is_Ma_NN;
        private object is_Ma_Vt;
        private object is_Ma_YC;
        private object is_So_Ct1;
        private object is_So_Ct2;
        private DataTable oCanNotDelete;
        private CTSXDataAccess oMethod;

        public FormCTSXLister()
        {
            this.oMethod = new CTSXDataAccess();
            this.id_Ngay_Ct1 = DBNull.Value;
            this.id_Ngay_Ct2 = DBNull.Value;
            this.is_So_Ct1 = DBNull.Value;
            this.is_So_Ct2 = DBNull.Value;
            this.is_Ma_YC = DBNull.Value;
            this.is_Ma_NN = DBNull.Value;
            this.is_Ma_Bp = DBNull.Value;
            this.is_Ma_Hd = DBNull.Value;
            this.is_Ma_Vt = DBNull.Value;
            this.is_Dien_Giai = DBNull.Value;
            this.is_Ghi_Chu = DBNull.Value;
            this.is_Ma_Loai1 = DBNull.Value;
            this.is_Ma_Loai2 = DBNull.Value;
            this.is_Ma_Loai3 = DBNull.Value;
            this.ii_FilterByUser = AppInstance.FilterByUser ? 1 : 0;
            this.InitializeComponent();
            base.MasterGridBrowser = this.grdMaster;
            base.DetailGridBrowser = this.grdDetail;
            (base.MasterGridBrowser.Columns[0] as StatusColumn).StatusField = 0;
            (base.MasterGridBrowser.Columns[1] as StatusColumn).StatusField = 1;
            this.OnResetControls();
            base.ResizeForm();
        }

        public FormCTSXLister(string ps_InvoiceCode)
        {
            this.oMethod = new CTSXDataAccess();
            this.id_Ngay_Ct1 = DBNull.Value;
            this.id_Ngay_Ct2 = DBNull.Value;
            this.is_So_Ct1 = DBNull.Value;
            this.is_So_Ct2 = DBNull.Value;
            this.is_Ma_YC = DBNull.Value;
            this.is_Ma_NN = DBNull.Value;
            this.is_Ma_Bp = DBNull.Value;
            this.is_Ma_Hd = DBNull.Value;
            this.is_Ma_Vt = DBNull.Value;
            this.is_Dien_Giai = DBNull.Value;
            this.is_Ghi_Chu = DBNull.Value;
            this.is_Ma_Loai1 = DBNull.Value;
            this.is_Ma_Loai2 = DBNull.Value;
            this.is_Ma_Loai3 = DBNull.Value;
            this.ii_FilterByUser = AppInstance.FilterByUser ? 1 : 0;
            this.InitializeComponent();
            base.InvoiceCode = ps_InvoiceCode;
            base.MasterGridBrowser = this.grdMaster;
            base.DetailGridBrowser = this.grdDetail;
            (base.MasterGridBrowser.Columns[0] as StatusColumn).StatusField = 0;
            (base.MasterGridBrowser.Columns[1] as StatusColumn).StatusField = 1;
            this.OnResetControls();
            base.ResizeForm();
        }

        private void AddNotDeleteInvoice(object pd_Ngay_Ct, object ps_So_Ct, object ps_Dien_Giai)
        {
            if (this.oCanNotDelete == null)
            {
                this.oCanNotDelete = new DataTable();
                this.oCanNotDelete.Columns.Add("Ngay_Ct", typeof(DateTime));
                this.oCanNotDelete.Columns.Add("So_Ct", typeof(string));
                this.oCanNotDelete.Columns.Add("Dien_Giai", typeof(string));
            }
            DataRow row = this.oCanNotDelete.NewRow();
            row["Ngay_Ct"] = pd_Ngay_Ct;
            row["So_Ct"] = ps_So_Ct;
            row["Dien_Giai"] = ps_Dien_Giai;
            this.oCanNotDelete.Rows.Add(row);
        }

        private bool CheckInvoiceLock(object ps_InvoiceOrder, bool pb_Locked)
        {
            string str = null;
            if (!this.CheckInvoiceLock(ps_InvoiceOrder, pb_Locked, ref str))
            {
                MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            return true;
        }

        private bool CheckInvoiceLock(object ps_InvoiceOrder, bool pb_Locked, ref string ps_WarningMessage)
        {
            int num = this.oMethod.CheckInvoiceLock(AppInstance.Subsidiary, AppInstance.UserName, ps_InvoiceOrder);
            if (((num == 7) || ((num == 5) && pb_Locked)) || ((num == 2) && !pb_Locked))
            {
                ps_WarningMessage = base.AppInvoiceParameters.LockedMessage(num, pb_Locked);
                return false;
            }
            this.oMethod.Lock(AppInstance.UserName, ps_InvoiceOrder, pb_Locked);
            return true;
        }

        private bool CheckInvoicePost(object ps_InvoiceOrder, int pi_Posted)
        {
            string str = null;
            int num = 0;
            if (this.CheckInvoicePost(ps_InvoiceOrder, pi_Posted, ref str, ref num))
            {
                return true;
            }
            if (num == 8)
            {
                base.AppInvoiceParameters.ShowInvoiceUsed(ps_InvoiceOrder, str);
            }
            else
            {
                MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            return false;
        }

        private bool CheckInvoicePost(object ps_InvoiceOrder, int pi_Posted, ref string ps_WarningMessage, ref int pi_Result)
        {
            pi_Result = this.oMethod.CheckInvoicePost(AppInstance.Subsidiary, AppInstance.UserName, ps_InvoiceOrder);
            if (((((pi_Result == 9) || (pi_Result == 8)) || (pi_Result == 7)) || ((pi_Result == 6) && (pi_Posted == 2))) || ((pi_Result == 3) && (pi_Posted == 0)))
            {
                ps_WarningMessage = base.AppInvoiceParameters.PostedMessage(pi_Result, pi_Posted);
                return false;
            }
            this.oMethod.Post(AppInstance.UserName, ps_InvoiceOrder, pi_Posted);
            return true;
        }

        private bool CheckInvoiceStatus(object ps_InvoiceOrder)
        {
            string str = null;
            int num = 0;
            if (this.CheckInvoiceStatus(ps_InvoiceOrder, ref str, ref num))
            {
                return true;
            }
            if (num == 8)
            {
                base.AppInvoiceParameters.ShowInvoiceUsed(ps_InvoiceOrder, str);
            }
            else
            {
                MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            return false;
        }

        private bool CheckInvoiceStatus(object ps_InvoiceOrder, ref string ps_WarningMessage, ref int pi_Result)
        {
            pi_Result = this.oMethod.CheckInvoiceStatus(AppInstance.Subsidiary, AppInstance.UserName, ps_InvoiceOrder);
            if (((pi_Result != 9) && (pi_Result != 8)) && (((pi_Result != 7) && (pi_Result != 6)) && (pi_Result != 5)))
            {
                return true;
            }
            ps_WarningMessage = base.AppInvoiceParameters.StatusMessage(pi_Result);
            return false;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            DataGridViewCellStyle style2 = new DataGridViewCellStyle();
            DataGridViewCellStyle style3 = new DataGridViewCellStyle();
            this.GridContainer = new SplitContainer();
            this.grdMaster = new GridControl();
            this.Column1 = new StatusColumn();
            this.Column2 = new StatusColumn();
            this.Column3 = new DataGridViewTextBoxColumn();
            this.Column4 = new DataGridViewTextBoxColumn();
            this.Column5 = new DataGridViewTextBoxColumn();
            this.Column6 = new DataGridViewTextBoxColumn();
            this.Column7 = new DataGridViewTextBoxColumn();
            this.Column8 = new DataGridViewTextBoxColumn();
            this.grdDetail = new GridControl();
            this.Column9 = new DataGridViewTextBoxColumn();
            this.Column10 = new DataGridViewTextBoxColumn();
            this.Column11 = new DataGridViewTextBoxColumn();
            this.Column13 = new DataGridViewTextBoxColumn();
            this.Column14 = new DataGridViewTextBoxColumn();
            this.Column22 = new NumericColumn();
            this.GridContainer.Panel1.SuspendLayout();
            this.GridContainer.Panel2.SuspendLayout();
            this.GridContainer.SuspendLayout();
            ((ISupportInitialize) this.grdMaster).BeginInit();
            ((ISupportInitialize) this.grdDetail).BeginInit();
            base.SuspendLayout();
            this.GridContainer.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.GridContainer.IsSplitterFixed = true;
            this.GridContainer.Location = new Point(0, 0x18);
            this.GridContainer.Name = "GridContainer";
            this.GridContainer.Orientation = Orientation.Horizontal;
            this.GridContainer.Panel1.Controls.Add(this.grdMaster);
            this.GridContainer.Panel2.Controls.Add(this.grdDetail);
            this.GridContainer.Size = new Size(0x31a, 0x1e3);
            this.GridContainer.SplitterDistance = 0xe3;
            this.GridContainer.SplitterWidth = 1;
            this.GridContainer.TabIndex = 13;
            this.grdMaster.AllowUserToAddRows = false;
            this.grdMaster.AllowUserToDeleteRows = false;
            this.grdMaster.CheckAutoSize = true;
            this.grdMaster.CheckColor = false;
            this.grdMaster.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdMaster.Columns.AddRange(new DataGridViewColumn[] { this.Column1, this.Column2, this.Column3, this.Column4, this.Column5, this.Column6, this.Column7, this.Column8 });
            this.grdMaster.Dock = DockStyle.Fill;
            this.grdMaster.Font = new Font("Arial", 8.25f);
            this.grdMaster.Location = new Point(0, 0);
            this.grdMaster.Name = "grdMaster";
            this.grdMaster.ReadOnly = true;
            this.grdMaster.Size = new Size(0x31a, 0xe3);
            this.grdMaster.TabIndex = 0;
            this.Column1.DataPropertyName = "Locked";
            style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            this.Column1.DefaultCellStyle = style;
            this.Column1.HeaderText = "";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Resizable = DataGridViewTriState.False;
            this.Column1.StatusField = 0;
            this.Column1.Width = 0x16;
            this.Column2.DataPropertyName = "Posted";
            style2.Alignment = DataGridViewContentAlignment.MiddleCenter;
            this.Column2.DefaultCellStyle = style2;
            this.Column2.HeaderText = "";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Resizable = DataGridViewTriState.False;
            this.Column2.StatusField = 0;
            this.Column2.Width = 0x16;
            this.Column3.DataPropertyName = "Ngay_Ct";
            this.Column3.HeaderText = "Ngày";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Resizable = DataGridViewTriState.False;
            this.Column3.Width = 0x3e;
            this.Column4.DataPropertyName = "So_Ct";
            this.Column4.HeaderText = "Số";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Width = 70;
            this.Column5.DataPropertyName = "Dien_Giai";
            this.Column5.HeaderText = "Diễn giải (VN)";
            this.Column5.Name = "Column5";
            this.Column5.ReadOnly = true;
            this.Column5.Width = 0x94;
            this.Column6.DataPropertyName = "Desc_EN";
            this.Column6.HeaderText = "Diễn giải (EN)";
            this.Column6.Name = "Column6";
            this.Column6.ReadOnly = true;
            this.Column6.Width = 0x93;
            this.Column7.DataPropertyName = "Ten_YC";
            this.Column7.HeaderText = "Người yêu cầu";
            this.Column7.Name = "Column7";
            this.Column7.ReadOnly = true;
            this.Column7.Width = 140;
            this.Column8.DataPropertyName = "Ten_NN";
            this.Column8.HeaderText = "Người nhận";
            this.Column8.Name = "Column8";
            this.Column8.ReadOnly = true;
            this.Column8.Resizable = DataGridViewTriState.True;
            this.Column8.Width = 140;
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new DataGridViewColumn[] { this.Column9, this.Column10, this.Column11, this.Column13, this.Column14, this.Column22 });
            this.grdDetail.Dock = DockStyle.Fill;
            this.grdDetail.Font = new Font("Arial", 8.25f);
            this.grdDetail.Location = new Point(0, 0);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.Size = new Size(0x31a, 0xff);
            this.grdDetail.TabIndex = 0;
            this.Column9.DataPropertyName = "Ma_Vt";
            this.Column9.HeaderText = "Mã vật tư";
            this.Column9.Name = "Column9";
            this.Column9.ReadOnly = true;
            this.Column9.Width = 80;
            this.Column10.DataPropertyName = "Ten_Vt";
            this.Column10.HeaderText = "Tên vật tư";
            this.Column10.Name = "Column10";
            this.Column10.ReadOnly = true;
            this.Column10.Width = 0x15f;
            this.Column11.DataPropertyName = "Dvt";
            this.Column11.HeaderText = "Đvt";
            this.Column11.Name = "Column11";
            this.Column11.ReadOnly = true;
            this.Column11.Width = 60;
            this.Column13.DataPropertyName = "Ma_Bp";
            this.Column13.HeaderText = "Bộ phận";
            this.Column13.Name = "Column13";
            this.Column13.ReadOnly = true;
            this.Column13.Width = 80;
            this.Column14.DataPropertyName = "Ma_Hd";
            this.Column14.HeaderText = "Hợp đồng";
            this.Column14.Name = "Column14";
            this.Column14.ReadOnly = true;
            this.Column14.Width = 80;
            this.Column22.DataPropertyName = "So_Luong9";
            style3.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.Column22.DefaultCellStyle = style3;
            this.Column22.HeaderText = "Số lượng";
            this.Column22.Name = "Column22";
            this.Column22.ReadOnly = true;
            this.Column22.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column22.UserTextNumericFormat = AppInstance.TextNumericFormat.Quantity;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.CheckAccountingInvoice = false;
            base.ClientSize = new Size(0x31a, 0x214);
            base.Controls.Add(this.GridContainer);
            base.Name = "FormCTSXLister";
            base.ShowBalanceButton = true;
            base.ShowPaymentButton = false;
            base.StoredProcedure = "Danh_So_CtSX";
            base.Controls.SetChildIndex(this.GridContainer, 0);
            this.GridContainer.Panel1.ResumeLayout(false);
            this.GridContainer.Panel2.ResumeLayout(false);
            this.GridContainer.ResumeLayout(false);
            ((ISupportInitialize) this.grdMaster).EndInit();
            ((ISupportInitialize) this.grdDetail).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        protected override void OnAdd()
        {
            base.LocalFormEditor = new FormCTSXEditor(base.AppInvoiceParameters);
            base.OnAdd();
        }

        protected override void OnBalance()
        {
            if (base.LocalMasterRow["Ngay_Ht"].Equals(DBNull.Value))
            {
                MessageBox.Show("Chưa xác định ngày hoàn thành!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                new FormCTSXF0Editor(base.MasterInvoiceOrder, base.LocalMasterRow).Show();
            }
        }

        protected override void OnCopy()
        {
            base.LocalFormEditor = new FormCTSXEditor(base.AppInvoiceParameters);
            base.OnCopy();
        }

        protected override void OnDelete()
        {
            if (MessageBox.Show(AppInstance.DeleMessage, AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if ((base.MasterGridBrowser.SelectedRows != null) && (base.MasterGridBrowser.SelectedRows.Count <= 1))
                {
                    DataRow row = ((DataRowView) base.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                    if (!this.CheckInvoiceStatus(row["Stt"]))
                    {
                        return;
                    }
                    this.oMethod.Delete(AppInstance.UserName, row["Stt"]);
                    base.LocalMasterTable.Rows.Remove(row);
                }
                else
                {
                    this.oCanNotDelete = null;
                    string str = null;
                    int num = 0;
                    foreach (DataGridViewRow row2 in base.MasterGridBrowser.SelectedRows)
                    {
                        DataRow row3 = ((DataRowView) row2.DataBoundItem).Row;
                        if (this.CheckInvoiceStatus(row3["Stt"], ref str, ref num))
                        {
                            this.oMethod.Delete(AppInstance.UserName, row3["Stt"]);
                            base.LocalMasterTable.Rows.Remove(row3);
                        }
                        else
                        {
                            this.AddNotDeleteInvoice(row3["Ngay_Ct"], row3["So_Ct"], str);
                        }
                    }
                    if ((this.oCanNotDelete != null) && (this.oCanNotDelete.Rows.Count > 0))
                    {
                        new FormNotDeletes(base.AppInvoiceParameters.DeletedMessage(), this.oCanNotDelete).ShowDialog();
                    }
                }
                base.OnDelete();
            }
        }

        protected override void OnEdit()
        {
            base.LocalFormEditor = new FormCTSXEditor(base.AppInvoiceParameters);
            base.OnEdit();
        }

        protected override void OnFillData()
        {
            base.LocalMasterTable = this.oMethod.GetMasterTable(AppInstance.Subsidiary, AppInstance.DaysFilter, this.id_Ngay_Ct1, this.id_Ngay_Ct2, this.is_So_Ct1, this.is_So_Ct2, base.InvoiceCode, this.is_Ma_YC, this.is_Ma_NN, this.is_Ma_Bp, this.is_Ma_Hd, this.is_Ma_Vt, this.is_Dien_Giai, this.is_Ma_Loai1, this.is_Ma_Loai2, this.is_Ma_Loai3, this.ii_FilterByUser, AppInstance.UserName, this.is_Ghi_Chu, this.ii_Posted, this.ii_Locked);
            base.OnFillData();
        }

        protected override void OnFilter()
        {
            FormCTSXFilter filter = new FormCTSXFilter();
            filter.Ngay_Ct1 = this.id_Ngay_Ct1;
            filter.Ngay_Ct2 = this.id_Ngay_Ct2;
            filter.So_Ct1 = this.is_So_Ct1;
            filter.So_Ct2 = this.is_So_Ct2;
            filter.Ma_YC = this.is_Ma_YC;
            filter.Ma_NN = this.is_Ma_NN;
            filter.Ma_Bp = this.is_Ma_Bp;
            filter.Ma_Hd = this.is_Ma_Hd;
            filter.Ma_Vt = this.is_Ma_Vt;
            filter.Dien_Giai = this.is_Dien_Giai;
            filter.Ghi_Chu = this.is_Ghi_Chu;
            filter.Ma_Loai1 = this.is_Ma_Loai1;
            filter.Ma_Loai2 = this.is_Ma_Loai2;
            filter.Ma_Loai3 = this.is_Ma_Loai3;
            filter.FilterByUser = this.ii_FilterByUser;
            filter.Posted = this.ii_Posted;
            filter.Locked = this.ii_Locked;
            filter.ShowDialog();
            if (filter.CheckAccepted)
            {
                this.id_Ngay_Ct1 = filter.Ngay_Ct1;
                this.id_Ngay_Ct2 = filter.Ngay_Ct2;
                this.is_So_Ct1 = filter.So_Ct1;
                this.is_So_Ct2 = filter.So_Ct2;
                this.is_Ma_YC = filter.Ma_YC;
                this.is_Ma_NN = filter.Ma_NN;
                this.is_Ma_Bp = filter.Ma_Bp;
                this.is_Ma_Hd = filter.Ma_Hd;
                this.is_Ma_Vt = filter.Ma_Vt;
                this.is_Dien_Giai = filter.Dien_Giai;
                this.is_Ghi_Chu = filter.Ghi_Chu;
                this.is_Ma_Loai1 = filter.Ma_Loai1;
                this.is_Ma_Loai2 = filter.Ma_Loai2;
                this.is_Ma_Loai3 = filter.Ma_Loai3;
                this.ii_FilterByUser = filter.FilterByUser;
                this.ii_Posted = filter.Posted;
                this.ii_Locked = filter.Locked;
                base.OnFilter();
            }
        }

        protected override void OnLock(bool pb_Locked)
        {
            if ((base.MasterGridBrowser.SelectedRows != null) && (base.MasterGridBrowser.SelectedRows.Count <= 1))
            {
                DataRow row = ((DataRowView) base.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                if (this.CheckInvoiceLock(row["Stt"], pb_Locked))
                {
                    row["Locked"] = pb_Locked;
                    base.LocalMasterRow["Locked"] = pb_Locked;
                }
            }
            else
            {
                this.oCanNotDelete = null;
                string str = null;
                foreach (DataGridViewRow row2 in base.MasterGridBrowser.SelectedRows)
                {
                    DataRow row3 = ((DataRowView) row2.DataBoundItem).Row;
                    if (this.CheckInvoiceLock(row3["Stt"], pb_Locked, ref str))
                    {
                        row3["Locked"] = pb_Locked;
                        if (base.LocalMasterRow["Stt"].Equals(row3["Stt"]))
                        {
                            base.LocalMasterRow["Locked"] = pb_Locked;
                        }
                    }
                    else
                    {
                        this.AddNotDeleteInvoice(row3["Ngay_Ct"], row3["So_Ct"], str);
                    }
                }
                if ((this.oCanNotDelete != null) && (this.oCanNotDelete.Rows.Count > 0))
                {
                    new FormNotDeletes(base.AppInvoiceParameters.LockedTitle(pb_Locked), this.oCanNotDelete).ShowDialog();
                }
            }
            base.OnLock(pb_Locked);
        }

        protected override void OnPause()
        {
            base.OnPause();
            if ((base.MasterGridBrowser.Rows.Count > 0) && (base.LocalMasterRow != null))
            {
                if (((DateTime) base.LocalMasterRow["Ngay_Ct"]) <= AppInstance.EndingDateOfSubEnterprice)
                {
                    MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    FormCTSXPause pause = new FormCTSXPause();
                    pause.MasterKey = base.MasterInvoiceOrder;
                    pause.Show();
                }
            }
        }

        protected override void OnPost(int pi_Posted)
        {
            if ((base.MasterGridBrowser.SelectedRows != null) && (base.MasterGridBrowser.SelectedRows.Count <= 1))
            {
                DataRow row = ((DataRowView) base.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                if (this.CheckInvoicePost(row["Stt"], pi_Posted))
                {
                    row["Posted"] = pi_Posted;
                    base.LocalMasterRow["Posted"] = pi_Posted;
                }
            }
            else
            {
                this.oCanNotDelete = null;
                string str = null;
                int num = 0;
                foreach (DataGridViewRow row2 in base.MasterGridBrowser.SelectedRows)
                {
                    DataRow row3 = ((DataRowView) row2.DataBoundItem).Row;
                    if (this.CheckInvoicePost(row3["Stt"], pi_Posted, ref str, ref num))
                    {
                        row3["Posted"] = pi_Posted;
                        if (base.LocalMasterRow["Stt"].Equals(row3["Stt"]))
                        {
                            base.LocalMasterRow["Posted"] = pi_Posted;
                        }
                    }
                    else
                    {
                        this.AddNotDeleteInvoice(row3["Ngay_Ct"], row3["So_Ct"], str);
                    }
                }
                if ((this.oCanNotDelete != null) && (this.oCanNotDelete.Rows.Count > 0))
                {
                    new FormNotDeletes(base.AppInvoiceParameters.PostedTitle(pi_Posted), this.oCanNotDelete).ShowDialog();
                }
            }
            base.OnPost(pi_Posted);
        }

        internal override void OnResetControls()
        {
            if (!base.AppInvoiceParameters.BilingualUsed)
            {
                base.MasterGridBrowser.Columns[5].Visible = false;
            }
            if (base.AppInvoiceParameters.AllowDepartmentControl != 2)
            {
                base.DetailGridBrowser.Columns[3].Visible = false;
            }
            if (base.AppInvoiceParameters.AllowContractControl != 2)
            {
                base.DetailGridBrowser.Columns[4].Visible = false;
            }
            base.OnResetControls();
        }

        internal override void OnShowMaster()
        {
            base.LocalMasterRow = this.oMethod.GetMasterDataRow(base.MasterInvoiceOrder);
            base.LocalDetailDataSet = this.oMethod.GetDetailDataSet(base.MasterInvoiceOrder);
            base.OnShowMaster();
        }
    }
}

